package org.baicaixiaozhan.springbootwebdemo1.security;

import org.baicaixiaozhan.springbootwebdemo1.util.HttpUtils;

/**
 * DESC: 仿写 Spring Security
 *
 * @author : baicaixiaozhan
 * @since : 2021-02-03
 */
public class SecurityExpressionOperations {

    public final boolean hasRole(String role) {
        return hasAnyRole(role);
    }

    public final boolean hasAnyRole(String... roles) {
        return hasAnyAuthorityName(roles);
    }

    private boolean hasAnyAuthorityName(String... roles) {
        String role = HttpUtils.getCurrentLoginUser().getUserRole().name();
        for (String s : roles) {
            if (role.equals(s)) {
                return true;
            }
        }
        return false;
    }
}
